from django.http import HttpResponse
from django.shortcuts import redirect
from django .utils.deprecation import MiddlewareMixin

class AuthMiddleware(MiddlewareMixin):
    """中间件"""
    """确保没登陆之前不能进入系统"""

    def process_request(self, request):
        # 1、读取当前访问的用户的session信息，有则代表一登陆过
        if request.path_info in ['/login/', '/image/code/']:
            return

        # 获取当前登录用户信息
        info_dic = request.session.get("info")
        print()

        if info_dic:
            return
        # 如果无登录信息，重定向回登录页面
        return redirect("/login/")



